package erlwitch.project.fileFilters;

import java.io.File;
import java.io.FilenameFilter;
import java.util.regex.Pattern;

/**
 * Reeplaza *.* por .*\..* (para que se parezca a regexps de DOS)
 * Solo acepta archivos que matchean con la regexp (transformada) NO directorios
 * @author Horacio
 *
 */
public class ArchiveRegExpFilter implements FilenameFilter {

	private Pattern pattern;
	
	public ArchiveRegExpFilter(String regExp) {
		String trueExp = regExp.replaceAll("\\.", "\\\\.").replaceAll("\\*", "\\.*");
		pattern = Pattern.compile(trueExp);
	}
	
	public boolean accept(File dir, String name) {
		File file = new File(dir, name);
		boolean ret = file.isFile() && pattern.matcher(name).matches();
		return ret;
	}

}
